Ambient Light Sensors with Auto Gain Switching Capabilities

ABSTRACT

An ambient light sensor that is operable in high gain mode and low gain mode is provided. The high gain mode may help provide satisfactory sensitivity at low light levels but may generate saturated output levels in bright ambient lighting conditions. Low gain mode may therefore be switched into use when bright ambient lighting conditions are detected. The ambient light sensor may be placed in high gain mode by default. An auto-gain switch controller may detect whether the ambient light reading is saturated during a given period of time. In response to determining that the ambient light reading is saturated for a programmable number of consecutive time periods, the auto-gain switch controller may reset and switch the ambient light sensor to the low gain mode. The gain state may optionally be embedded into the ambient light sensor output.

This application is a continuation of U.S. patent application Ser. No.14/849,147, filed Sep. 9, 2015, which is hereby incorporated byreference herein in its entirety. This application claims the benefit ofand claims priority to U.S. patent application Ser. No. 14/849,147,filed Sep. 9, 2015.

BACKGROUND

This relates generally to electronic devices, and, more particularly, tolight sensors for electronic devices.

Electronic devices such as laptop computers, cellular telephones, andother equipment are sometimes provided with light sensors. For example,ambient light sensors may be incorporated into a device to provide thedevice with information on current lighting conditions. Ambient lightreadings may be used in controlling the device. If, for example brightdaylight conditions are detected, an electronic device may increasedisplay brightness to compensate.

In conventional electronic device displays, the display brightness maystill be too dim when being operated in bright daylight conditions(i.e., the maximum display brightness setting may not be capable ofoutputting a sufficient luminance level to properly display content tothe user in sunny outdoor conditions). Allowing the display brightnessto always toggle to an even higher brightness setting whenever brightambient light conditions are detected may, however, consume an excessiveamount of power.

It would therefore be desirable to be able to provide improved sensorsfor electronic device such as improved ambient light sensors.

SUMMARY

An electronic device may be provided with a display mounted in ahousing. In accordance with an embodiment, the electronic device mayinclude control circuitry in the housing and an ambient light sensor inthe housing with which the control circuitry measures an ambient lightintensity, where the ambient light sensor is operable in a plurality ofgain states and is configured to filter out high intensity pulses. Thecontrol circuitry may include an auto gain switching (AGS) control logicthat places the ambient light sensor in one of the plurality of gainstates.

The auto gain switching control logic may include a saturation detectionmodule that detects when the ambient light sensor exhibits a saturatedsensor output. The auto gain switching control logic may also include apersistency checking module that determines whether the ambient lightsensor exhibits a saturated sensor output in a consecutive number ofpersistency checking intervals. The number of persistency checkinginterval that is checked by the persistency checking module may bedynamically programmable.

The ambient light sensor may be configured in an auto gain switchingenabled mode and an auto gain switching disabled mode. In the AGSdisabled mode, the control circuitry manually sets the ambient lightsensor in a fixed gain state. In the AGS enabled mode, the ambient lightsensor may be placed in the plurality of gain states and may exhibit areduced analog-to-digital conversion (ADS) resolution relative to theAGS disabled mode.

In accordance with another suitable embodiment, a method for operatingan electronic device that includes an ambient light sensor is provided.The method includes using the ambient light sensor to output an ambientlight sensor reading to the control circuitry, using auto gain switching(AGS) control logic in the ambient light sensor to place the ambientlight sensor in a plurality of gain states, and using the auto gainswitching control logic to switch from one gain state to another gainstate in the plurality of gain states while filtering out spurious noisesources. The control circuitry may be used to adjust the brightness of adisplay in the electronic device depending on the magnitude of theambient light sensor reading.

The method may also include setting the ambient light sensor to a highgain state at the beginning of an integration period. The method alsoincludes monitoring the ambient light sensor reading for saturationduring a persistency checking period that is a subset of the integrationperiod, and determining whether a persistency checking condition issatisfied by verifying whether the ambient light sensor reading hasconsistently saturated during the entirety of the persistency checkingperiod. In response to determining that the persistency checking is notsatisfied, the ambient light sensor may continue operating in the highgain state. In response to determining that the persistency checkingcondition is satisfied, the ambient light sensor may be adjusted to alow gain state. When the ambient light sensor is in the low gain state,the ambient light sensor may be reset back to the high gain state at theend of the integration period.

The accordance with some embodiments, the system may allow dynamicadjustment of the duration of the persistency checking period to set thestrength of the filtering operation. If desired, the gain state of theambient light sensor may also be embedded in the ambient light sensorreading.

Further features of the invention, its nature and various advantageswill be more apparent from the accompanying drawings and followingdetailed description.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a schematic diagram of an illustrative electronic devicehaving a light sensor in accordance with an embodiment.

FIG. 2 is a perspective view of a portion of an electronic devicedisplay having an ambient light sensor in accordance with an embodiment.

FIG. 3 is a cross-sectional side view of an illustrative light sensorthat is being mounted in accordance with an embodiment.

FIG. 4 is a diagram of an illustrative light sensor with auto gainswitching capabilities in accordance with an embodiment.

FIG. 5 is a timing diagram that illustrates the operation of a lightsensor of the type shown in FIG. 4 in accordance with an embodiment.

FIG. 6 is a diagram showing two different modes in which the lightsensor of FIG. 4 may be operated in accordance with an embodiment.

FIG. 7 is a flow chart of illustrative steps for operating a lightsensor of the type shown in FIG. 4 in accordance with an embodiment.

DETAILED DESCRIPTION

An illustrative electronic device of the type that may be provided withone or more light sensors is shown in FIG. 1. Electronic device 10 maybe a computing device such as a laptop computer, a computer monitorcontaining an embedded computer, a tablet computer, a cellulartelephone, a media player, or other handheld or portable electronicdevice, a smaller device such as a wrist-watch device, a pendant device,a headphone or earpiece device, a device embedded in eyeglasses or otherequipment worn on a user's head, or other wearable or miniature device,a television, a computer display that does not contain an embeddedcomputer, a gaming device, a navigation device, an embedded system suchas a system in which electronic equipment with a display is mounted in akiosk or automobile, equipment that implements the functionality of twoor more of these devices, or other electronic equipment.

As shown in FIG. 1, electronic device 10 may have control circuitry 16.Control circuitry 16 may include storage and processing circuitry forsupporting the operation of device 10. The storage and processingcircuitry may include storage such as hard disk drive storage,nonvolatile memory (e.g., flash memory or otherelectrically-programmable-read-only memory configured to form a solidstate drive), volatile memory (e.g., static or dynamicrandom-access-memory), etc. Processing circuitry in control circuitry 16may be used to control the operation of device 10. The processingcircuitry may be based on one or more microprocessors, microcontrollers,digital signal processors, baseband processors, power management units,audio chips, application specific integrated circuits, etc.

Input-output circuitry in device 10 such as input-output devices 12 maybe used to allow data to be supplied to device 10 and to allow data tobe provided from device 10 to external devices. Input-output devices 12may include buttons, joysticks, scrolling wheels, touch pads, key pads,keyboards, microphones, speakers, tone generators, vibrators, cameras,light-emitting diodes and other status indicators, data ports, etc. Auser can control the operation of device 10 by supplying commandsthrough input-output devices 12 and may receive status information andother output from device 10 using the output resources of input-outputdevices 12.

Input-output devices 12 may include one or more displays such as display14. Display 14 may be a touch screen display that includes a touchsensor for gathering touch input from a user or display 14 may beinsensitive to touch. A touch sensor for display 14 may be based on anarray of capacitive touch sensor electrodes, acoustic touch sensorstructures, resistive touch components, force-based touch sensorstructures, a light-based touch sensor, or other suitable touch sensorarrangements.

Input-output devices 12 may also include sensors 18. Sensors 18 mayinclude an ambient light sensor and other sensors (e.g., a capacitiveproximity sensor, a light-based proximity sensor, a magnetic sensor, anaccelerometer, a force sensor, a touch sensor, a temperature sensor, apressure sensor, a compass, a microphone or other sound sensor, or othersensors). An ambient light sensor may be provided with auto gainswitching (AGS) capabilities. In particular, the ambient light sensormay be operable in multiple different gain modes. For example, theambient light sensor may be configured in a high gain mode in responseto detecting dark ambient lighting conditions (e.g., to help increasesensitivity in low light conditions) and may be configured in a low gainmode in response to detecting bright ambient lighting conditions (e.g.,to help avoid charge saturation in sunny outdoor conditions).Selectively configuring the ambient light sensor in different gain modesby monitoring the amount of ambient light can help extend the dynamicrange of the ambient light sensor. If desired, information from othersensors (e.g., an orientation sensor, a camera, etc.) may be used incombination with information from the ambient light sensor (e.g., todetermine how device 10 is oriented relative to the viewer, etc.).

A perspective view of a portion of an illustrative electronic device isshown in FIG. 2. In the example of FIG. 2, device 10 includes a displaysuch as display 14 mounted in housing 22. Housing 22, which maysometimes be referred to as an enclosure or case, may be formed ofplastic, glass, ceramics, fiber composites, metal (e.g., stainlesssteel, aluminum, etc.), other suitable materials, or a combination ofany two or more of these materials. Housing 22 may be formed using aunibody configuration in which some or all of housing 22 is machined ormolded as a single structure or may be formed using multiple structures(e.g., an internal frame structure, one or more structures that formexterior housing surfaces, etc.).

Display 14 may be protected using a display cover layer such as a layerof transparent glass, clear plastic, sapphire, or other clear layer.Openings may be formed in the display cover layer. For example, anopening may be formed in the display cover layer to accommodate abutton, a speaker port, or other components. Openings may be formed inhousing 22 to form communications ports (e.g., an audio jack port, adigital data port, etc.), to form openings for buttons, etc.

Display 14 may include an array of display pixels formed from liquidcrystal display (LCD) components, an array of electrophoretic pixels, anarray of plasma pixels, an array of organic light-emitting diode pixelsor other light-emitting diodes, an array of electrowetting pixels, orpixels based on other display technologies. The array of pixels ofdisplay 14 forms an active area AA. Active area AA is used to displayimages for a user of device 10. Active area AA may be rectangular or mayhave other suitable shapes. Inactive border area IA may run along one ormore edges of active area AA. Inactive border area IA may containcircuits, signal lines, and other structures that do not emit light forforming images. To hide inactive circuitry and other components inborder area IA from view by a user of device 10, the underside of theoutermost layer of display 14 (e.g., the display cover layer or otherdisplay layer) may be coated with an opaque masking material such as alayer of black ink.

Optical components (e.g., a camera, a light-based proximity sensor, anambient light sensor, status indicator light-emitting diodes, cameraflash light-emitting diodes, etc.) may be mounted under inactive borderarea IA. One or more openings (sometimes referred to as windows) may beformed in the opaque masking layer of the inactive border area IA toaccommodate the optical components. For example, a light componentwindow such as an ambient light sensor window may be formed in aperipheral portion of display 14 such as region 20 in inactive borderarea IA. Ambient light from the exterior of device 10 may be measured byan ambient light sensor in device 10 after passing through region 20 andthe display cover layer.

FIG. 3 is a cross-sectional side view of display 14 of FIG. 2 takenalong line 24 and viewed in direction 25 of FIG. 2. As shown in FIG. 3,light sensor 26 may be mounted in alignment with window 20. Light sensor26 may be an ambient light sensor that is used in measuring ambientlight from various light sources. Display cover layer 30 has an outersurface such as surface 34. Window 20 may be formed from an opening inopaque masking layer 28 on inner surface 32 of display cover layer 30 ininactive area IA. Layer 30 may be formed from glass, plastic, ceramic,sapphire, or other transparent materials and may be a part of display 14or a separate protective layer that covers active display structures.The opening associated with window 20 may be filled with window material36. Window material 36 may be material that is transparent to some orall of the visible light spectrum. For example, window material 36 maybe filled from a clear or translucent polymer or other transparentmaterial. Window material 36 may, if desired, include diffuser materialand/or material that forms a Fresnel lens or other light directingfeatures that help guide incoming light 42 to light sensor 26.

Conventional ambient light sensors with a single fixed gain setting havelimited dynamic range. Consider a scenario in which a first ambientlight sensor has a relatively high sensitivity to light. In low lightconditions, the first ambient light sensor may function wonderfully todetect the amount of light that is present. In brighter lightconditions, however, the first ambient light sensor may be easilysaturated and may therefore not be capable of providing any usefulinformation. Consider another scenario in which a second ambient lightsensor exhibits a relatively low sensitivity to light. In bright lightconditions, the second ambient light sensor may function properly todetect the mount of light that is present without being constantlysaturated. In low light conditions, however, the second ambient lightsensor may not be sensitive enough to be able to capture any usefulinformation.

It would therefore be desirable to provide improved light sensors thatis operable in multiple different gain modes. In accordance with anembodiment, light sensors are provided that can be configured in a highgain mode (e.g., a mode that exhibits high sensitivity to light), a lowgain mode (e.g., a mode that exhibits low sensitivity to light), andoptionally one or more intermediate gain modes (e.g., one or more modesthat exhibit moderate sensitivity to light). For example, an ambientlight sensor may be configured in a high gain mode in response todetecting that the device is being operated in low light conditions ormay be configured in a low gain mode in response to detecting that thedevice is being operated in bright light conditions.

The high gain mode may exhibit a gain that is 10 times the gain of thelow gain mode (as an example). As another example, the high gain modemay exhibit a gain that is 20 times the gain of the low gain mode. Asyet another example, the high gain mode may exhibit a gain that is 40times the gain of the low gain mode. These examples are merelyillustrative. In general, the light sensor may have any number ofprogrammable gain settings (e.g., at least two configurable gainsettings, four or more configurable gain settings, eight or moreconfiguration gain settings, etc.) that can adjust the relative strengthof the high gain mode to the low gain mode. Operating light sensorsusing multiple programmable gain settings can help extend the dynamicrange of the light sensors.

One common application of light sensors is adjusting the displaybrightness in response to the amount of ambient light that is currentlybeing detected. For example, the display may be dimmed in low ambientlight conditions so that the display is not unnecessary bright (whichcan also help reduce power consumption), whereas the display may be madebrighter in bright ambient light conditions so that the display can bemore easily viewed by the user. In sunny conditions, however,conventional displays may still not be bright enough to adequatelydisplay content to the user (i.e., the display is still too dim evenwhen it is configured to output at its maximum luminance level).

In accordance with an embodiment, an electronic device display may beprovided with an outdoor viewing mode that is capable of providingsubstantially higher luminance levels at the expense of display viewingangle. When the display is configured in this outdoor viewing mode, thedisplay may be bright enough to adequately display content to the usereven under sunny conditions. Since the outdoor viewing mode outputssubstantially brighter images and therefore consumes more power, itwould be desirable to ensure that the outdoor viewing mode is accuratelyenabled and not constantly being activated by false triggering events.

For example, consider a scenario in which a device is being operated atnight in a relatively low light environment. The device may include anambient light sensor that is appropriately configured in a high gainmode and may also include a display that is outputting content at itsnormal viewing mode (e.g., a viewing mode that has a brightness settingthat is substantially lower than that of the outdoor viewing mode).

In real world environments, it is common for the device to experienceshort duration high intensity pulses in low light conditions such ascamera flash. If care is not taken, the ambient light sensor may detectthese high intensity pulses and can inadvertently reconfigure itself tooperate in the low gain mode and thereby trigger the display to operatein the outdoor viewing mode, both of which are not suitable foroperation in low light environment. The selective switching of lightsensor gain modes from high to low or vice versa (a mechanism that issometimes referred to as “auto gain switching” or AGS) should thereforebe able to filter out such short duration high intensity pulses so as toprevent the inadvertent switching of light sensor gain modes. Inaccordance with an embodiment of the present invention, this can beaccomplished via a programmable filter, which can be realized byimplementing a programmable persistency checking period before allowingthe gain to switch.

FIG. 4 is a diagram of an illustrative light sensor with auto gainswitching (AGS) capabilities, where the AGS is provided with aprogrammable persistency checking mechanism. As shown in FIG. 4, a lightsensor 26 such as an ambient light sensor may include a light detector100, a data converter 102, a buffer circuit 104, and associated AGScontrol logic 106. In general, ambient light sensor 26 may be formedfrom a semiconductor substrate such as a silicon substrate. One or moredetectors 100 such as phototransistors, photodiodes, or otherphotodetectors that is capable of detecting incoming light may be formedon the semiconductor substrate.

Detector 100 may be coupled to an input of data converter 102. Dataconverter 102 may be an analog-to-digital converter (ADC) circuit thatreceives an amount of charge from the photosensitive detector 100 andgenerates a corresponding digital output that is proportional to theamount of charge that is received from detector 100. Analog-to-digitalconverter 102 may be a ramp A/D converter, successive approximation A/Dconverter, a flash A/D converter, a hybrid A/D converter employing acombination of these data converting architectures, and other suitabletypes of data converters. Data converter 102 may exhibit any suitableresolution (e.g., 10-bit ADC resolution, 12-bit ADC resolution, 15-bitADC resolution, 16-bit ADC resolution, etc.).

Digital data output from A/D converter 102 may be temporarily stored inbuffer circuit 104. Latching the ADC output using buffer 104 can allowthe light detector 100 to being the next integration cycle withoutdelay. The buffered output may be fed to external host control circuitry16 (e.g., control circuitry 16 described in connection with FIG. 1) viapath 112 and also internally to AGS control logic 106 via path 113.Depending on the data that is received from light sensor 26 over path112, host control circuitry 16 may be configured to adjust the displaybrightness of the electronic device, to adjust the interferenceappearance of the device, or take other suitable action.

In particular, host control circuitry 16 may also be capable of enablingor disabling the AGS functionality of light sensor 26 by selectivelyasserting AGS enable signal AGSen that is provided to AGS control logic106 via path 114. When signal AGSen is asserted (e.g., when AGSen islogic “1”), light sensor 26 may be operable in multiple gain modes toenable extended dynamic range. When signal AGSen is deasserted (e.g.,when AGSen is logic “0”), light sensor 26 may be operated in a fixedgain mode that is manually set by the host control circuitry 16. Forexample, host control circuitry 16 may manually configure light sensor26 in a nominal low gain mode when the AGS functionality is disabled. Asanother example, control circuitry 16 may manually configure lightsensor 26 in a high gain mode that exhibits a gain that is equal to apredetermined integer multiple of the nominal low gain mode when the AGSfunctionality is deactivated. Each of interconnect paths 112 and 114 maybe implemented using an I2C serial bus, a serial peripheral interface(SPI), a universal serial bus (USB), a PCIe bus, a serial AT attachment(SATA) bus, or other types of peripheral bus for communicating withcontrol circuitry 16.

As shown in FIG. 4, auto gain switch control logic 106 may be providedwith a saturation detection mechanism 108 and a programmable persistencychecking mechanism 110. Configured in this way, AGS control logic 106may be able to detect whether the ADC output provided over path 113 hasbeen saturated. Detection of a saturation event may indicate that thecurrent sensitivity of the light sensor is too high (i.e., that the gainmode ought to be switched to a lower gain mode). In accordance with anembodiment, the saturation detection may be operated in conjunction withprogrammable persistency checking mechanism 110 to help minimizeinadvertent switching of gain modes (e.g., to help filter out highintensity light pulses that ought to be ignored).

The persistency checking may involve verifying that the ADC output hassaturated consistently over an extended period of time. As an example,the persistency checking criteria may require that the ADC outputsaturates for four consecutive cycles. If the ADC output saturates foronly three cycles and then becomes unsaturated during the persistencychecking period, the persistency checking criteria will not be met. If,however, the ADC output saturates for at least four consecutive cyclesduring the persistency checking period, the persistency checkingcriteria is satisfied, and the AGS control logic 106 may be allowed totoggle the gain state of light sensor 26. In the arrangement of FIG. 4,AGS control logic 106 may provide gain control signals Gain_Sel, resetsignals Rst, and/or other control/initialization signals to dataconverter 102 via path 116. For example, the AGS control logic 106 mayconfigured A/D converter 102 in a low gain mode by setting signalsGain_Sel to “00,” in a high gain mode by setting signals Gain_Sel to“11,” or in some intermediate gain mode by setting Gain_Sel to “01” or“10.”

The requirement of four consecutive saturation detection events ismerely exemplary and does not serve to limit the scope of the presentinvention. In general, the number of consecutive saturation detectionevents that is required by the persistency checking mechanism may beprogrammable to provide additional flexibility in filtering outdifferent types of noise (e.g., the persistency checking criteria mayrequire less than four consecutive saturation events to be detected ormore than four consecutive saturation events to be detected). Operatingthe AGS control logic 106 in this way can help filter out spurious highintensity light pulses in low light environments.

FIG. 5 is a timing diagram that illustrates the operation of lightsensor 26 of the type described in connection with FIG. 4. The timeperiod from t0-t3 may represent one integration cycle. From time t0-t1,light sensor 26 may be initialized (e.g., A/D converter 102 may be resetand auto-zeroed, photodetector 100 may also be reset, etc.). Inaccordance with an embodiment, the light sensor may be initialized tohigh gain mode by default. Initializing the light sensor to high gainmode may be advantageous since it is easier to be saturated when thesensitivity is high. If however, the sensitivity is set to a low valueby default, the light sensor will not know to switch back to high gainmode even if it is being operated in low ambient light conditions.

The time period from t1-t2 may represent the persistency checkingperiod. The light sensor may be operated in high gain mode during theentirety of the persistency checking period. The persistency checkingperiod may include m unit checking intervals (or cycles) Tunit. Eachinterval Tunit may be 5 milliseconds (ms) in duration (as an example).As described above, the number of intervals Tunit that is checked duringthe persistency checking period may be programmable (e.g., m may beadjusted).

During each Tunit, saturation detection module 108 (FIG. 4) maydetermine whether the ADC output is saturated. In one suitablearrangement, programmable persistency checking module 110 may include acounter that increments whenever a saturation event is detected. Thecounter may be reset to zero at the beginning of the persistencychecking period at time t1. At the end of the persistency checkingperiod (at time t2), the current value of this counter may be comparedto the programmable value m. If the counter value is less than m, theAGS persistency checking condition has not been met (i.e., at least oneTunit exhibits an unsaturated ADC output). If the counter value is equalto m, the AGS persistency checking condition is satisfied (i.e., the ADCoutput has saturated during each and every Tunit between time t1 andt2). The logic AND gate shown in FIG. 5 may be an actual hardwareimplementation or may merely be a schematic representation of thebehavior that is realized by the persistency checking module.

In response to determining that the AGS persistency condition has notbeen satisfied, the light sensor may continue operating in high gainmode for the remainder of the integration time (e.g., from cycle m+1,m+2, . . . , N). In this scenario, the total integration time will beequal to N times the duration of Tunit.

In response to determining that the AGS persistency condition has beenmet, the AGS control logic 106 may reset the photodetector, optionallyperforming auto-zeroing operations on A/D converter 102 (at time t2),and then send appropriate control signals to A/D converter 102 to switchconverter 102 from high gain mode to a lower gain mode. In the exampleof FIG. 5, the reset/auto-zeroing operations may last one Tunit. In suchscenario, the effective integration time will be restarted and willtherefore be equal to (N−m−1) times the duration of Tunit. This ismerely illustrative. In general, the reset/auto-zeroing operations maylast k Tunits. In such cases, the effective integration time will berestarted and will be equal to (N−m−k) times the duration of Tunit. Inthis approach, the high gain mode integration time from time t1 to t3(when the AGS persistency condition is not met) is always greater thanthe low gain mode integration time, which is a subset of the period fromtime t2-t3. The parameter N may generally be set by system levelconstraints.

At the end of the integration time (at time t3), the light sensor may bereset back to high gain mode (if necessary), and another integrationtime may be automatically initiated or the system may wait for some timebefore beginning another integration.

FIG. 6 is a diagram showing how light sensor 26 of the type shown inFIG. 4 may further be operated in an AGS enabled mode and an AGSdisabled mode. As described in connection with FIG. 4, AGS control logic106 may receive an asserted enable signal AGSen that places the lightsensor in the AGS enabled mode 600. When the auto gain switchingcapability is enabled, the light sensor (e.g., the A/D converter) may beplaced in different gain modes.

In accordance with an embodiment, the current gain state of the lightsensor may be embedded in one or more most significant bits (MSB) in theambient light sensor output. As an example, an MSB of “0” may reflect ahigh gain mode, whereas an MSB of “1” may be indicative of a low gainmode. Since high gain mode is indicative of a lower lux level, low gainresults should be numerically larger than high gain results for easierdigital comparison. Embedding the gain state as part of the light sensoroutput can help reduce the number of serial interface transactions withthe host control circuitry, thereby minimizing the response time betweenthe ambient light sensor reading and the display brightness control.

When enable signal AGSen is deasserted, the light sensor may be placedin an AGS disabled mode 602. When the auto gain switching capability isdisabled, the light sensor (e.g., the A/D converter) may be placed in afixed gain mode that is manually set by the host controller. The A/Dconverter may be manually set to low gain mode or high gain mode whenthe light sensor is operated in state 602. Since the host controlcircuitry knows the current gain setting of the ambient light sensor, nobits in the ADC output need to be reserved for the gain setting and fullADC resolution can be enabled. In other words, the ADC resolution inmode 602 may be greater than the ADC resolution in mode 600 (since mode600 reserves one or more bits to encode the current gain state of theambient light sensor). The light sensor may be placed back in state 600by reasserting enable signal AGSen.

FIG. 7 is a flow chart of illustrative steps for operating a lightsensor of the type described in connection with the embodiments of FIGS.1-6, where the light sensor is operated in the AGS enabled mode (e.g.,signal AGSen has been asserted). At step 700, the photosensitive element100 and the A/D converter 102 may be properly initialized (e.g., byperforming suitable resetting and calibration operations). At step 702,the A/D converter may be set to high gain mode by default at thebeginning of the integration period.

At step 704, the AGS control logic may be used to monitor whether thelight sensor output saturates during the persistency checking period. Inparticular, the AGS control logic may include a saturation detectionmodule for detecting when a saturation event has occurred and also aprogrammable persistency checking module for determining whether or notthe persistency condition has been satisfied (at step 706). For example,the persistency checking module may be configured to verify whether theADC output has saturated for a programmable number of consecutivepersistency check cycles (e.g., described as interval Tunit in FIG. 5).

In response to detecting that the AGS persistency condition has not bemet, the light sensor may continue integrating in the high gain mode (atstep 708). In response to detecting that the AGS persistency conditionhas been met, the light sensor may be configured to switch to low gainmode (at step 710). During this time, the photodetector and the A/Dconverter may be reset in preparation for the low gain mode integration.At step 712, the low gain mode integration may begin.

Processing may proceed to step 714 from either step 708 or 712. At step714, device 10 (FIG. 1) may use control circuitry 16 to take a suitableaction such as adjusting a display brightness setting for display 14,adjusting the appearance of items displayed on display 14 (e.g., iconshading and texture, shading and texture for other items on display 14,etc.), taking other actions to adjust the operation of device 10, etc.At step 716, the device may optionally adjust the duration of thepersistency checking period if it determines that a stronger or weakerfiltering effect might be more appropriate given the current operatingconditions. For example, the persistency checking period may belengthened to increase the filtering strength or may be shortened todecrease the filtering strength.

The foregoing is merely illustrative and various modifications can bemade by those skilled in the art without departing from the scope andspirit of the described embodiments. The foregoing embodiments may beimplemented individually or in any combination.

What is claimed is:
 1. An electronic device comprising: a housing; anambient light sensor in the housing that generates an ambient lightsensor output and includes an analog-to-digital converter operable in aplurality of gain states; and control circuitry in the housing thatmeasures ambient light intensity using the ambient light sensor outputand that switches the analog-to-digital converter from a first gainstate in the plurality of gain states to a second gain state in theplurality of gain states in response to the ambient light sensor output.2. The electronic device defined in claim 1, wherein the controlcircuitry selectively enables the ambient light sensor in an auto gainswitching mode that allows the ambient light sensor to operate in theplurality of gain states.
 3. The electronic device defined in claim 1,wherein the ambient light sensor comprises: an auto gain switching (AGS)control logic that places the ambient light sensor in one of theplurality of gain states.
 4. The electronic device defined in claim 3,wherein the auto gain switching control logic includes a saturationdetection mechanism that detects when the ambient light sensor output issaturated.
 5. The electronic device defined in claim 4, wherein the autogain switching control logic includes a module that determines whetherthe ambient light sensor output is saturated during a plurality ofconsecutive intervals.
 6. The electronic device defined in claim 5,wherein the number of intervals in the plurality of consecutiveintervals is programmable.
 7. The electronic device defined in claim 2,wherein the control circuitry sets the ambient light sensor in a fixedgain state in response to disabling the auto gain switching mode.
 8. Theelectronic device defined in claim 7, wherein the ambient light sensorexhibits a first analog-to-digital conversion (ADC) resolution when theauto gain switching mode is enabled and a second analog-to-digitalconversion resolution that is greater than the first analog-to-digitalconversion resolution when the auto gain switching mode is disabled. 9.A method for operating an electronic device having a housing, controlcircuitry in the housing, and an ambient light sensor in the housing,the method comprising: using an analog-to-digital converter in theambient light sensor to output an ambient light sensor reading to thecontrol circuitry; and using auto gain switching (AGS) control logic inthe ambient light sensor to place the analog-to-digital converter in oneof a plurality of gain states based on the ambient light sensor reading.10. The method defined in claim 9, wherein the electronic device furtherincludes a display in the housing, the method further comprising: usingthe control circuitry to adjust a brightness level of the display basedon the ambient light sensor reading.
 11. The method defined in claim 9,further comprising: with the auto gain switching control logic, settingthe ambient light sensor to a high gain state at the beginning of anintegration period.
 12. The method defined in claim 11, furthercomprising: monitoring the ambient light sensor reading for saturationduring a monitoring period that is a subset of the integration period.13. The method defined in claim 12, further comprising: determiningwhether the ambient light sensor reading is saturated during theentirety of the monitoring period.
 14. The method defined in claim 13,further comprising: in response to determining that the ambient lightsensor reading is not saturated during the entirety of the monitoringperiod, continuing to operate the ambient light sensor in the high gainstate; and in response to determining that the ambient light sensorreading is saturated during the entirety of the monitoring period,setting the ambient light sensor to a low gain state.
 15. The methoddefined in claim 12, further comprising: adjusting the duration of themonitoring period.
 16. A light sensor that detects ambient light,comprising: a photosensitive element; an analog-to-digital converterthat receives charge from the photosensitive element and generates acorresponding output; and an auto gain switching (AGS) controller thatconfigures the analog-to-digital converter in one of a plurality of gainmodes based on the corresponding output.
 17. The light sensor defined inclaim 16, wherein the auto gain switching controller includes asaturation detection mechanism that detects whether the output of theanalog-to-digital converter is saturated.
 18. The light sensor definedin claim 17, wherein the auto gain switching controller includes acounter for counting how often the output of the analog-to-digitalconverter is saturated during a persistency checking period.
 19. Thelight sensor defined in claim 18, wherein the auto gain switchingcontroller configures the analog-to-digital converter in another one ofthe plurality of gain modes in response to determining that the counterhas a count that is equal to a predetermined threshold while maintainingthe gain mode of the analog-to-digital converter in response todetermining that the count is less than the predetermined threshold. 20.The light sensor defined in claim 19, wherein the auto gain switchingcontroller is further configured to reset the analog-to-digitalconverter and to switch the analog-to-digital converter from a high gainmode in the plurality of gain modes to a low gain mode in the pluralityof gain modes in response to determining that the count is equal to thepredetermined threshold.